package com.ww.springboot.boot.algorithm.leetcode1;

import com.ww.springboot.boot.utils.ObjectUtil;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * 描述：
 *
 * @author 🧑 ‍wanwei
 * @since 2023-02-18 17:36
 */
public class CYdemo {

    public static void main(String[] args) {


        List<String> ss = new ArrayList<>();
        ss.add("1");
        ss.add("2");
        ss.add("3");
        ss.add("4");
        ss.add("5");

        List<String> combine = combine(ss);
        combine.sort(Comparator.naturalOrder());
        System.out.println(combine.size());
        System.out.println(combine);
    }


    /**
     * @param ss
     * @return
     */
    private static List<String> combine(List<String> ss) {
        List<String> listTotal = new ArrayList<>();

        for (int i = 0; i < ss.size(); i++) {
            listTotal = combine(listTotal, ss.get(i));
        }
        return listTotal;
    }

    /**
     * 将list 与 s
     *
     * @param list
     * @param s
     * @return
     */
    private static List<String> combine(List<String> list, String s) {
        List<String> newList = new ArrayList<>();
        if (ObjectUtil.isEmpty(list)) {
            newList.add(s);
            return newList;
        }

        for (int i = 0; i < list.size(); i++) {
            String ss = list.get(i);
            for (int j = 0; j <= ss.length(); j++) {
                newList.add(ss.substring(0, j) + s + ss.substring(j));
            }
        }
        return newList;
    }


}
